<html>
  <head>
    <title>Edit User</title>
   	<script src="./lib/jquery.js" ></script>
	<meta name="viewport" content="width=device-width, initial-scale=1"> 
	<link rel="stylesheet" href="./lib/jquery.mobile-1.1.1.min.css" />
	<script src="./lib/jquery-1.7.1.min.js"></script>
	<script language="JavaScript" SRC="config.js"></script>
	<script src="./lib/jquery.mobile-1.1.1.min.js"></script>
	<script type="text/javascript" charset="utf-8">
	 var query = window.location.search;
	 var form=document.forms["form"];
	  // Skip the leading ?, which should always be there, 
	  // but be careful anyway
	  if (query.substring(0, 1) == '?') {
	    query = query.substring(1);
	  }
	  var data = query.split(','); 
	   alert(data[0]);
	  for (i = 0; (i < data.length); i++) {
	    data[i] = unescape(data[i]);
	    data[i]=data[i].replace('announcement_id=','');
	  }
	function init()
	{
		 alert("init is called="+data[0]);
		 $.post('http://'+serverip+'/socialengine/mobileservice/announcement/getannouncementfromid', {announcement_id:data[0]},
		            function(output){
		               alert('fill value');
		            	for(key in output.Data) {
		               		var body=(output.Data[key].body.replace('<p>','')).replace('</p>','');
		               $("#title").val(output.Data[key].title);
		               $("#body").val(body);
		            	}
		            },"json");
	}
	function get()
	{
		 var form=document.forms["form"];
	 if(form.title.value=='')
		 {
		 alert("Title must not empty");
		 }
	 else if(form.body.value=='')
		 {
		 alert("Body must not empty");
		 }
	 else 
		 {
 		 alert("get is called");
 		
        $.post('http://'+serverip+'/socialengine/mobileservice/announcement/editannouncement', {announcement_id:data[0],title:form.title.value,body: form.body.value},
            function(output){
               alert(output.result);
               window.location.href = "announcement.html";
            },"json");
      
		 }
    };
    </script>
  </head>
<body onload="init()">
<div data-role="page" id="header">
<div data-role="header">
<a href="index.html" data-role="button" data-icon="home" data-iconpos="notext" rel="external">Home</a>
<h1>Edit Announcement</h1>
</div>
<div data-role="content">
<p><a href="#terms" data-role="button" data-icon="delete" data-iconpos="notext">Delete</a> Delete Announce</p>
<form name="form" id="form">
	<p>Title</p>
    <input type="text" name="title" id="title">
    <p>Content</p>
    <textarea name="body" id="body"  rows="6" cols="20"></textarea>
    <input type="button" value="Edit Announcement" onClick="get();">
</form>
</div>
<div data-role="footer">
<h4>Footer</h4>
</div>
</div>
<div data-role="dialog" id="terms">
	<div data-role="header">
		<h1>Are you sure</h1>
	</div>
	
	<div data-role="content" data-theme="c">	
		Do you agree  to these terms?
		<br><br>
		<a data-role="button" data-inline="true" data-rel="back" data-theme="a">Disagree</a>		
		<a href="javascript:agreedelete();" data-role="button" data-inline="true">Agree</a>
	</div>
	<script>
		function agreedelete() {
			// process dialog...
			 alert("delete ann is called");
        $.post('http://'+serverip+'/socialengine/mobileservice/announcement/deleteannouncement', {announcement_id:data[0]},
            function(output){
               alert(output.result);
               $('.ui-dialog').dialog('close');
               window.location.href = "announcement.html";
            },"json");
			// close dialog
			
		}
	</script>
</div>
</body>
</html>